<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/8
 * Time: 17:32
 */

namespace app\index\controller;

use app\index\model\Role;
use think\Controller;
use think\Cookie;
use think\Hook;
use think\Request;
use think\Session;
use app\index\model\Admin;

class CommonController extends Controller{

    public function _initialize(){

        //请求的控制器，传到行为处理函数中，判断用户是否有执行的权限
        $instanceinfo = Request::instance()->url();

        Hook::listen('Authcheck',$instanceinfo);

        if(!Cookie::has('auth')){
            $this->error("请重新登录",'Login/index',1);
        }else{
            $username = explode('-',Cookie::get("auth"))[0];

            $urole_id = Admin::where("uname",$username)->value('urole');

            $rp_id = Role::where("r_id",$urole_id)->value('rp_id');

            $sel_arr = explode(',',$rp_id);

            $power_arr = \app\index\model\Controller::all($sel_arr);


            //权限内容传递到公共模版中
            $qx = [];
            $i = 1;
            foreach($power_arr as $k){
                $qx[$i]["p_id"] = $k->c_id;
                $qx[$i]["p_action"] = $k->c_con;
                $qx[$i]["p_content"] = $k->c_status;
                $i++;
            }

            //dd($qx);exit;


            $this->assign("qx",$qx);

           // Cookie::set("auth",Cookie::get("auth"),3600);
        }
    }

}
